//@author A0096723X
#include "CommonUtils.h"

const QTime CommonUtils::TIME_MIDNIGHT= QTime::fromString("0000", "hhmm");
const string CommonUtils::STRING_COMMAND_ADD= "add";
const string CommonUtils::STRING_COMMAND_DELETE="delete";
const string CommonUtils::STRING_COMMAND_SET_DONE="done";
const string CommonUtils::STRING_COMMAND_EDIT="edit";
const string CommonUtils::STRING_COMMAND_DISPLAY="display";
const string CommonUtils::STRING_COMMAND_DISPLAY_ALL="displayall";
const string CommonUtils::STRING_COMMAND_SEARCH="search";
const string CommonUtils::STRING_COMMAND_UNDO="undo";
const string CommonUtils::STRING_COMMAND_REDO="redo";
const string CommonUtils::STRING_COMMAND_DISPLAY_TASK="displayt";
const string CommonUtils::STRING_COMMAND_DISPLAY_EVENT="displaye";
const string CommonUtils::STRING_COMMAND_DISPLAY_WEEK="displayw";
const string CommonUtils::STRING_COMMAND_DISPLAY_DAY="displayd";
const string CommonUtils::STRING_COMMAND_DISPLAY_TODAY="displaytoday";
const string CommonUtils::STRING_COMMAND_DISPLAY_DAY_BEFORE="displaydb";
const string CommonUtils::STRING_COMMAND_CLEAR="clear";
const string CommonUtils::STRING_COMMAND_DISPLAY_DONE="displaydone";
const string CommonUtils::STRING_COMMAND_EXIT="exit";
const string CommonUtils::ENTRY_TYPE_EVENT= "EVENT";
const string CommonUtils::ENTRY_TYPE_TASK= "TASK";
const string CommonUtils::STRING_HEADER_TODAY= "Today:";
const string CommonUtils::STRING_HEADER_TOMORROW="Tomorrow:";
const string CommonUtils::STRING_HEADER_FUTURE="Future:";
const string CommonUtils::STRING_HEADER_OVERDUE= "Overdue:";
const QString CommonUtils::FORMAT_DATE="dd/MM/yyyy";
const QString CommonUtils::FORMAT_DATE_HEADER = "dddd, dd MMM";
const QString CommonUtils::FORMAT_TIME="hhmm";

CommonUtils::CommonUtils(void)
{
}


CommonUtils::~CommonUtils(void)
{
}



void CommonUtils::assignDate(const Entry* entry, QDate &date, QTime &time) {
	date = entry->getStartDate();
	time = entry->getStartTime();
	if(!time.isValid() || !date.isValid()) {
		date = entry->getEndDate();
		time = entry->getEndTime();
	}
}

string CommonUtils::toLower(string input) {
	for(int i=0; i<input.length(); input[i]=tolower(input[i]), i++);
	return input;
}
bool CommonUtils::greater(const Entry* a, const Entry* b)
{
	QDate aDate;
	QTime aTime;
	assignDate(a, aDate, aTime);
	QDate bDate;
	QTime bTime;
	assignDate(b, bDate, bTime);
	if (QDateTime(aDate,aTime) == QDateTime(bDate, bTime))
		return a->getName() < b->getName();

	return QDateTime(aDate,aTime) < QDateTime(bDate,bTime);
}